package com.crane.oss.sports;

import com.crane.common.framework.http.apache.HttpClientUtils;
import com.crane.common.framework.http.apache.HttpResult;
import com.crane.oss.xunfei.req.*;
import com.crane.oss.xunfei.resp.*;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zx
 */
@Component
public class XunFeiAppApiService extends XunFeiApiService {
    /**
     * 查询班级学生课堂列表
     */
    public ApiListResponse<AppAnalysisStudentClassCourseResp> getStudentClassCourse(QueryAppAnalysisStudentClassCourseReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/analysis/class/mini/student/courses/"+request.getStudentId(), params);
        if (httpResult.isSuccess()) {
            ApiListResponse<AppAnalysisStudentClassCourseResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<AppAnalysisStudentClassCourseResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    /**
     * 查询老师学生课堂列表
     */
    public ApiListResponse<AppAnalysisStudentClassCourseResp> getTeacherClassCourse(QueryAppAnalysisTeacherClassCourseReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/analysis/class/mini/teacher/courses/"+request.getTeacherId(), params);
        if (httpResult.isSuccess()) {
            ApiListResponse<AppAnalysisStudentClassCourseResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<AppAnalysisStudentClassCourseResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }


    /**
     * 学生风采
     */
    public ApiListResponse<AppAnalysisStudentPictureResp> getStudentPicture(QueryAppAnalysisStudentPictureReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/analysis/class/mini/student/picture/"+request.getStudentId(), params);
        if (httpResult.isSuccess()) {
            ApiListResponse<AppAnalysisStudentPictureResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<AppAnalysisStudentPictureResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    /**
     * 学生体制健康报告
     */
    public ApiSingleResponse<AppStudentPhysicalReportResp> getAppStudentPhysicalReport(QueryAppStudentPhysicalReportReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/physical/test/mini/student/report/"+request.getStudentId()+"/"+request.getSportCycleId(), params);
        if (httpResult.isSuccess()) {
            ApiSingleResponse<AppStudentPhysicalReportResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<AppStudentPhysicalReportResp>>() {
            });
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }

    /**
     * 学生运动处方
     */
    public ApiSingleResponse<AppStudentPrescriptionReportResp> getAppStudentPrescription(QueryAppStudentPhysicalReportReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/prescription/info/mini/student", params);
        if (httpResult.isSuccess()) {
            ApiSingleResponse<AppStudentPrescriptionReportResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<AppStudentPrescriptionReportResp>>() {
            });
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }


    /**
     * 学生运动处方详情
     */
    public ApiSingleResponse<String> getAppStudentPrescriptionDetail(QueryAppStudentPhysicalReportDetailReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/prescription/info/mini/student/detail", params);
        if (httpResult.isSuccess()) {
            ApiSingleResponse<String> response = httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<String>>() {
            });
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }

    /**
     * 家长首页
     */
    public ApiListResponse<AppParentIndexResp> getParentIndex(QueryAppParentIndexReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/analysis/class/mini/index/student/"+request.getStudentId(), params);
        if (httpResult.isSuccess()) {
            ApiListResponse<AppParentIndexResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<AppParentIndexResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }


    /**
     * 老师首页
     */
    public ApiListResponse<AppTeacherIndexResp> getTeacherIndex(QueryAppTeacherIndexReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/analysis/class/mini/index/teacher/"+request.getTeacherId(), params);
        if (httpResult.isSuccess()) {
            ApiListResponse<AppTeacherIndexResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<AppTeacherIndexResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    public static void main(String[] args) {
        XunFeiAppApiService xunFeiApiService=new XunFeiAppApiService();

//        QueryAppAnalysisStudentClassCourseReq queryAppAnalysisStudentClassCourseReq =new QueryAppAnalysisStudentClassCourseReq();
//        queryAppAnalysisStudentClassCourseReq.setStudentId("1");
//        queryAppAnalysisStudentClassCourseReq.setBeginTime(1647657145000L);
//        queryAppAnalysisStudentClassCourseReq.setEndTime(1652927545000L);
//        queryAppAnalysisStudentClassCourseReq.setPage(1);
//        queryAppAnalysisStudentClassCourseReq.setLimit(10);
//        System.out.println(xunFeiApiService.getStudentClassCourse(queryAppAnalysisStudentClassCourseReq,"87", null,"3"));

//        QueryAppAnalysisTeacherClassCourseReq queryAppAnalysisTeacherClassCourseReq=new QueryAppAnalysisTeacherClassCourseReq();
//        queryAppAnalysisTeacherClassCourseReq.setTeacherId("3");
//        queryAppAnalysisTeacherClassCourseReq.setFlag(1);
//        queryAppAnalysisTeacherClassCourseReq.setBeginTime(1647657145000L);
//        queryAppAnalysisTeacherClassCourseReq.setEndTime(1652927545000L);
//        queryAppAnalysisTeacherClassCourseReq.setPage(2);
//        queryAppAnalysisTeacherClassCourseReq.setLimit(10);
//        System.out.println(xunFeiApiService.getTeacherClassCourse(queryAppAnalysisTeacherClassCourseReq,"87", null,"3"));

//        QueryAppAnalysisStudentPictureReq queryAppAnalysisStudentPictureReq=new QueryAppAnalysisStudentPictureReq();
//        queryAppAnalysisStudentPictureReq.setStudentId("1");
//        queryAppAnalysisStudentPictureReq.setPage(1);
//        queryAppAnalysisStudentPictureReq.setLimit(10);
//        System.out.println(xunFeiApiService.getStudentPicture(queryAppAnalysisStudentPictureReq,"87", null,"3"));

//        QueryAppStudentPhysicalReportReq queryAppStudentPhysicalReportReq=new QueryAppStudentPhysicalReportReq();
//        queryAppStudentPhysicalReportReq.setStudentId("1");
//        queryAppStudentPhysicalReportReq.setSportCycleId("cycle-2021-2022");
       // System.out.println(xunFeiApiService.getAppStudentPhysicalReport(queryAppStudentPhysicalReportReq,"87", null,"3"));
      //  System.out.println(xunFeiApiService.getAppStudentPrescription(queryAppStudentPhysicalReportReq,"87", null,"3"));


//        QueryAppStudentPhysicalReportDetailReq queryAppStudentPhysicalReportDetailReq=new QueryAppStudentPhysicalReportDetailReq();
//        queryAppStudentPhysicalReportDetailReq.setPrescriptionId("d10fcbc2c72747c985837a6fe0108c60");
//        System.out.println(xunFeiApiService.getAppStudentPrescriptionDetail(queryAppStudentPhysicalReportDetailReq,"87", null,"3"));

//        QueryAppParentIndexReq queryAppStudentPhysicalReportReq=new QueryAppParentIndexReq();
//        queryAppStudentPhysicalReportReq.setStudentId("1");
//         System.out.println(xunFeiApiService.getParentIndex(queryAppStudentPhysicalReportReq,"87", null,"3"));

        QueryAppTeacherIndexReq queryAppTeacherIndexReq=new QueryAppTeacherIndexReq();
        queryAppTeacherIndexReq.setTeacherId("3");
        System.out.println(xunFeiApiService.getTeacherIndex(queryAppTeacherIndexReq,"87", null,"3"));
    }
}

